#include <cstdio>
#include <cstring>
#define maxn 2000010
int n, x, tot;
int bg[maxn], ed[maxn];
int next[maxn], extend[maxn];
char s[maxn], t[maxn];
bool b[2][maxn];
struct trie
{
    int son[26], leaf, cnt;
    void init()
    {
        memset(son, 0, sizeof (son));
        leaf = cnt = 0;
    }
} tree[maxn];
void exKMP(int flag, char S[], char T[], int x)
{
    int j, k, lenS = strlen(S + 1), lenT = strlen(T + 1);
    //next
    j = 0;
    while (T[j + 1] == T[j + 2] && j + 2 <= lenT) ++j;
    next[2] = j, k = 2;
    for (int i = 3; i <= lenT; ++i)
    {
        int Len = k + next[k] - 1, L = next[i - k + 1];
        if (L < Len - i + 1) next[i] = L;
        else
        {
            j = Len - i + 1 > 0 ? Len - i + 1 : 0;
            while (T[i + j] == T[1 + j]) ++j;
            next[i] = j, k = i;
        }
    }
    //extend
    j = 0;
    while (T[j + 1] == S[j + 1] && j + 1 <= lenS && j + 1 <= lenT) ++j;
    extend[1] = j, k = 1;
    for (int i = 2; i <= lenS; ++i)
    {
        int Len = k + extend[k] - 1, L = next[i - k + 1];
        if (L < Len - i + 1) extend[i] = L;
        else
        {
            j = Len - i + 1 > 0 ? Len - i + 1 : 0;
            while (T[1 + j] == S[i + j]) ++j;
            extend[i] = j, k = i;
        }
    }
    for (int i = 1; i <= lenS; ++i)
        if (extend[i] == lenS - i + 1)
            b[flag][i + x] = 1;
}
void insert(int k)
{
    int rt = 0;
    for (int i = bg[k]; i <= ed[k]; ++i)
    {
        tree[rt].cnt += b[0][i];
        int ch = s[i] - 'a';
        if (!tree[rt].son[ch])
        {
            tree[rt].son[ch] = ++tot;
            tree[tot].init();
        }
        rt = tree[rt].son[ch];
    }
    ++tree[rt].leaf;
}
int main()
{
    while (~scanf("%d", &n))
    {
        memset(b, 0, sizeof (b));
        x = tot = 0;
        tree[0].init();
        for (int i = 0; i < n; ++i)
        {
            int len;
            scanf("%d%s", &len, s + x + 1);
            for (int j = 1; j <= len; ++j)
                t[x + j] = s[x + len - j + 1];
            t[x + len + 1] = 0;
            exKMP(0, s + x, t + x, x);
            exKMP(1, t + x, s + x, x);
            bg[i] = x + 1;
            x += len;
            ed[i] = x;
            insert(i);
        }
        long long ans = 0;
        for (int i = 0; i < n; ++i)
        {
            int rt = 0;
            for (int j = ed[i]; j >= bg[i]; --j)
            {
                rt = tree[rt].son[s[j] - 'a'];
                if (!rt) break;
                if (b[1][ed[i] - j + bg[i] + 1] || j == bg[i])
                    ans += tree[rt].leaf;
            }
            if (rt) ans += tree[rt].cnt;
        }
        printf("%lld\n", ans);
    }
    return 0;
}
